﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.displayBoard
{
    public partial class MoldChangingScheduleEntityProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<MoldChangingScheduleEntity> entryList = new List<MoldChangingScheduleEntity>();

            MoldChangingScheduleEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new MoldChangingScheduleEntity();
                    entry.ActSetupStart = item[MoldChangingScheduleEntity.ACT_SETUP_START].ToString();
                    entry.ActSetupTime = Convert.ToDecimal(item[MoldChangingScheduleEntity.ACT_SETUP_TIME].ToString());
                    entry.Description = item[MoldChangingScheduleEntity.DESCRIPTION].ToString();
                    entry.EstimatedTime = item[MoldChangingScheduleEntity.ESTIMATED_TIME].ToString();
                    if (string.IsNullOrEmpty(entry.EstimatedTime))
                    {
                        entry.EstimatedTime = item[MoldChangingScheduleEntity.ACT_SETUP_START].ToString();
                    }

                    entry.Job = item[MoldChangingScheduleEntity.JOB].ToString();
                    entry.Machine = item[MoldChangingScheduleEntity.MACHINE].ToString();
                    entry.CurrentMold = item[MoldChangingScheduleEntity.CURRENTMOLD].ToString();
                    entry.LastMold = item[MoldChangingScheduleEntity.LASTMOLD].ToString();
                    entry.Part = item[MoldChangingScheduleEntity.PART].ToString();
                    entry.SetupStd = item[MoldChangingScheduleEntity.SETUP_STD].ToString();
                    entry.TimeToGo = Convert.ToDecimal(item[MoldChangingScheduleEntity.TIME_TO_GO].ToString());
                    entry.NR = int.Parse(item[MoldChangingScheduleEntity.N_R].ToString());
                    entry.Type = item[MoldChangingScheduleEntity.TYPE].ToString();
                    entry.User = item[MoldChangingScheduleEntity.USER].ToString();
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
